#include <iostream>
using namespace std;

int global_flag = 0;

bool valid(char* str) {
	if ((str[0]<'0' || str[0]>'9') && (str[0]!='+' && str[0]!='-'))
		return false;

	for (int i=1; i<strlen(str); i++) {
		if (str[i]<'0' || str[i]>'9')
			return false;
	}

	return true;
}

int str_int(char* str) {
	if (str==NULL || *str=='\0') {
		cout<<"null pointer"<<endl;
		global_flag = -1;
		return -1;
	}

	if (!valid(str)) {
		cout<<"invalid input"<<endl;
		global_flag = -2;
		return -1;
	}

	int flag = 1, begin = 1;
	if (str[0] == '-')
		flag = 0;
	else if (str[0] == '+')
		flag = 1;
	else
		begin = 0;

	int result = 0;
	for (int i=begin; i<strlen(str); i++) 
		result = result*10 + str[i] - '0';

	if (!flag)
		result = 0 - result;

	return result;
}

//int main() {
//	int res1 = str_int("-1234");
//	int res2 = str_int("+1234");
//	int res3 = str_int("1234");
//
//	return 0;
//}